package com.cwf.security.handle;

import com.cwf.security.utils.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @description: 授权失败处理
 * @return:
 * @author 18068
 * @date: 2022/9/25 21:19
 */
@Slf4j
@Component
public class AccessDeniedHandlerImp implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {


        Map<String,Object> res = new HashMap<>();
        res.put("code",403);
        res.put("msg","权限不足");

        log.warn("\n{}",res.toString());

        ResponseUtil.send(response,res);

        //System.out.println("权限不足");
    }
}
